package com.biz.primus.model.misc.vo;

import com.biz.primus.model.misc.constants.SMSConstants;
import com.biz.primus.model.misc.enums.MessageType;
import com.biz.primus.model.misc.enums.SignaturePosition;
import com.biz.primus.model.misc.utils.MessageTextUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @author yanweijin
 * @date 2017/6/1
 */
public abstract class SendRequestVo extends ChannelBasedAuth {


    private static final long serialVersionUID = -8147703800907893269L;
    @JsonIgnore
    private String signature = SMSConstants.SMS_SIGNATURE;

    /**
     * 暂时保留字段,用于传递类似阿里大鱼的短信模板id
     */
    private String templateId;

    private String content;

    private MessageType type = MessageType.auto;

    private SignaturePosition signaturePosition = SignaturePosition.head;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date expireAt;

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }

    public String getTemplateId() {
        return templateId;
    }

    public void setTemplateId(String templateId) {
        this.templateId = templateId;
    }

    public SignaturePosition getSignaturePosition() {
        return signaturePosition;
    }

    public void setSignaturePosition(SignaturePosition signaturePosition) {
        this.signaturePosition = signaturePosition;
    }


    public Date getExpireAt() {
        return expireAt;
    }

    public void setExpireAt(Date expireAt) {
        this.expireAt = expireAt;
    }

    public MessageType getType() {
        if (type == MessageType.auto) {
            return StringUtils.contains(content, "验证码") ? MessageType.validcode : MessageType.notice;
        }
        return type;
    }

    public void setType(MessageType type) {
        this.type = type;
    }

    @JsonIgnore
    public String getFullText() {
        return MessageTextUtils.getMessageFullText(signaturePosition, signature, content);
    }
}
